package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划相关接口")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiOperation("获取所有护理计划")
    public ResponseResult<List<NursingPlanVo>> getAllPlan() {
        List<NursingPlanVo> allNursingPlan
                = nursingPlanService.getAllNursingPlan();
        return ResponseResult.success(allNursingPlan);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult<NursingPlanVo> getPlanById(@ApiParam(value = "护理计划id") @PathVariable Long id) {
        NursingPlanVo nursingPlanById = nursingPlanService.getNursingPlanById(id);
        return ResponseResult.success(nursingPlanById);
    }

    @PutMapping("{id}")
    @ApiOperation("修改护理计划")
    public ResponseResult updatePlan(@PathVariable Long id, @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.updateNursingPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    @PostMapping()
    @ApiOperation("新增护理计划")
    public ResponseResult addPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        log.info("接收到护理计划信息: {}", nursingPlanDto);
        nursingPlanService.addNursingPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    @GetMapping("/search")
    @ApiOperation("分页条件查询")
    public ResponseResult<PageResponse<NursingPlanVo>>
    getPlanByPage(@ApiParam(value = "计划名称") String name,
                  @ApiParam(value = "计划状态:启用1，禁用0") Integer status,
                  @ApiParam(value = "页码") Integer pageNum,
                  @ApiParam(value = "每页条数") Integer pageSize) {
        PageResponse planPage = nursingPlanService.getPlanByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(planPage);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理计划")
    public ResponseResult deleteById(@ApiParam(value = "护理计划id") @PathVariable Long id) {
        nursingPlanService.deleteById(id);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用护理项目")
    public ResponseResult updateStatusById(@ApiParam(value = "护理计划id")
                                           @PathVariable Long id,
                                           @ApiParam(value = "状态")
                                           @PathVariable Integer status) {
        nursingPlanService.updateStatusById(id, status);
        return ResponseResult.success();
    }
    }
